package com.yzzrjy.controller.mainservlet.user;

import com.yzzrjy.Service.UserService;
import com.yzzrjy.bean.*;
import com.yzzrjy.util.ResponseUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet(name = "GetOnlineServlet", value = "/getOnline")
public class GetOnlineServlet extends HttpServlet {
    private UserService userService = new UserService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String uid = request.getParameter("uid");
        String token = request.getParameter("token");
        String sex = request.getParameter("sex");
        String page = request.getParameter("page");
        if(uid == null || token == null || sex == null || page == null){
            ResponseUtils.parameterError(response);
            return;
        }
        try {
            List<UserShowBean> list = userService.getOnlineUserList(uid, sex, Integer.parseInt(page));
            if(list == null){
                ResponseUtils.notFindError(response, "用户列表为空");
                return;
            }
            ResponseUtils.success(response, list);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
